package cn.wolfcode.trip.admin.web.controller;

import cn.wolfcode.trip.admin.util.UploadUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

//操作图片资源的控制器
@Controller
@RequestMapping("/image")
public class ImageController {

    @RequestMapping("/upload")
    @ResponseBody
    public Object upload(@RequestParam MultipartFile upload) {
        //把上传的图片保存到本地图库
        String url = UploadUtil.upload(upload);
        //并且把图片的地址返回
        //{"url":url, "status":1}
        Map<String, Object> map = new HashMap<>();
        map.put("url", url);
        map.put("uploaded", 1);
        return map;
    }
}
